import logging

import requests

logger = logging.getLogger('request_utils')


class RequestUtils:
    sess = requests.Session()
    pubilc_params = {}

    def send_request(self, **kwargs):
        """接收符合要求的参数，发送对应请求，打印日志"""
        logger.info('正在发送请求...')
        params = kwargs.get("params", {})
        params.update(self.pubilc_params)
        kwargs["params"] = params

        for k, v in kwargs.items():
            logger.info(f'  参数内容为【{k}：{v}】')

        resp = self.sess.request(**kwargs)

        logger.info('收到接口响应')
        logger.info(f'  状态码：{resp.status_code}')
        logger.info(f'  响应头：{resp.headers}')
        # logger.info(f'  响应正文：{resp.text}')

        return resp

# a = RequestUtils()
# logging.basicConfig(level=logging.INFO)
# resp = a.send_request(
#     method="get",
#     url="https://api.weixin.qq.com/cgi-bin/token",
#     params={
#         "grant_type": "client_credential",
#         "appid": "wx3f13087e9b9e3a3f",
#         "secret": "02707c607ac22e41046330bf749b7dbe"
#     }
# )
# print(resp.status_code)
